unit untConfiguracoes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxContainer, cxEdit, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy, dxSkinGlassOceans,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSharp, dxSkinSilver, dxSkinSpringTime,
  dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, cxGroupBox, cxLabel, cxTextEdit, Menus, StdCtrls,
  cxButtons, cxMaskEdit, cxDropDownEdit, IniFiles, cxButtonEdit, ExtDlgs,
  dxSkinCaramel;

type
  TfrmConfiguracoes = class(TForm)
    gbbConexao: TcxGroupBox;
    lblServidor: TcxLabel;
    edtServidor: TcxTextEdit;
    lblBanco: TcxLabel;
    edtBanco: TcxTextEdit;
    edtUsuario: TcxTextEdit;
    edtSenha: TcxTextEdit;
    lblUsuario: TcxLabel;
    lblSenha: TcxLabel;
    btnTestar_Conexao: TcxButton;
    grpSkin: TcxGroupBox;
    cbbSkin: TcxComboBox;
    btnSalvar: TcxButton;
    lblSkin: TcxLabel;
    lblPlanoFundo: TcxLabel;
    OpenPictureDialog1: TOpenPictureDialog;
    edtFigura: TcxButtonEdit;
    procedure btnSalvarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnTestar_ConexaoClick(Sender: TObject);
    procedure edtFiguraPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmConfiguracoes: TfrmConfiguracoes;

implementation
uses untDataModule, untPricipal, UntFormPrincipal_NavBar;
{$R *.dfm}

{ TfrmConfiguracoes }

procedure TfrmConfiguracoes.btnSalvarClick(Sender: TObject);
begin
  DM.vServidor := edtServidor.Text;
  DM.vBanco    := edtBanco.Text;
  DM.vUsuario  := edtUsuario.Text;
  DM.vSenha    := edtSenha.Text;
  DM.vSkin     := cbbSkin.ItemIndex;
  DM.vFigura   := edtFigura.Text;
  DM.SalvarIni;
  DM.SalvarIni_Tela;
  DM.AtualizarTela;
  frmPrincipal_NavBar.imgPrincipal.Picture.LoadFromFile(DM.vFigura);
end;

procedure TfrmConfiguracoes.btnTestar_ConexaoClick(Sender: TObject);
begin
  try

    DM.FBCONNECTION.Connected      := False;
    DM.FBCONNECTION.LoginPrompt    := False ;
    DM.FBCONNECTION.Params.Values['HostName']   := edtServidor.Text;
    DM.FBCONNECTION.Params.Values['Database']   := edtBanco.Text;
    DM.FBCONNECTION.Params.Values['User_Name']  := edtUsuario.Text;
    DM.FBCONNECTION.Params.Values['Password']   := edtSenha.Text;

    DM.FBCONNECTION.ConnectionName := 'FirebirdConnection';
    DM.FBCONNECTION.DriverName     := 'Firebird';
    DM.FBCONNECTION.GetDriverFunc  := 'getSQLDriverINTERBASE';
    DM.FBCONNECTION.LibraryName    := 'dbxfb.dll';
    DM.FBCONNECTION.VendorLib      := 'fbclient.dll';
    DM.FBCONNECTION.Params.Values['DriverName'] := 'Interbase';

    DM.FBCONNECTION.Connected := True;

  except
    on E: Exception do
    begin
      Application.MessageBox(PChar('Erro ao conectar o banco de dados Origem :'+#13#10+E.Message), '', MB_ICONERROR);
      Abort;
    end;
  end;
end;

procedure TfrmConfiguracoes.edtFiguraPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  OpenPictureDialog1.Title := 'Abrir Figura';
  OpenPictureDialog1.InitialDir := 'C:\\Meus Documentos\\Minhas Imagens\';
  if OpenPictureDialog1.Execute then
    edtFigura.Text := OpenPictureDialog1.FileName;
end;


procedure TfrmConfiguracoes.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    Perform(Wm_NextDlgCtl,0,0);
  end;
end;

procedure TfrmConfiguracoes.FormShow(Sender: TObject);
begin
  edtServidor.Text  := DM.vServidor;
  edtBanco.Text     := DM.vBanco;
  edtUsuario.Text   := DM.vUsuario;
  edtSenha.Text     := DM.vSenha;
  cbbSkin.ItemIndex := DM.vSkin;
  edtFigura.Text    := DM.vFigura;
end;

end.
